// 
// Copyright 2010 Classpath Pty Ltd <opensource@classpath.com.au>
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 

using build

**
** Tests the `CanUseTableOptions` mixin.
**
internal class CanUseTableOptionsTest : Test {

    **
    ** Stores an instance of `CanUseTableOptions` for testing.
    **
    CanUseTableOptions? canUseTableOptions

    **
    ** Performs additional setup needed for `CanUseTableOptionsTest`.
    **
    override Void setup() {
        super.setup()
        canUseTableOptions = CanUseTableOptionsTestClass()
    }

    **
    ** Cleans up additional setup needed for `CanUseTableOptionsTest`.
    **
    override Void teardown() {
        super.teardown()
        canUseTableOptions = null
    }

    **
    ** Tests the `CanUseTableOptions.check` method.
    **
    Void testCheck() {
        option := canUseTableOptions.check("check_name", "check_rule")
        verifyEq(CheckTableOption#, option.typeof)
        verifyEq("check_name", (option as CheckTableOption).name)
        verifyEq("check_rule", (option as CheckTableOption).check)
        verifyEq(1, canUseTableOptions.modifications.size)
        verifyEq(option, canUseTableOptions.modifications[0])
    }

    **
    ** Tests the `CanUseTableOptions.index` method.
    **
    Void testIndex() {
        option := canUseTableOptions.index("index_name", ["column_name_1", "column_name_2"])
        verifyEq(IndexTableOption#, option.typeof)
        verifyEq("index_name", (option as IndexTableOption).name)
        verifyEq(2, (option as IndexTableOption).columns.size)
        verifyEq(["column_name_1", "column_name_2"], (option as IndexTableOption).columns)
        verifyEq(1, canUseTableOptions.modifications.size)
        verifyEq(option, canUseTableOptions.modifications[0])
    }

    **
    ** Tests the `CanUseTableOptions.foreignKey` method.
    **
    Void testForeignKey() {
        reference := canUseTableOptions.references("referenced_table_name", ["referenced_column_name_1", "referenced_column_name_2"])
        verifyEq(Reference#, reference.typeof)
        verifyEq("referenced_table_name", reference.table)
        verifyEq(2, reference.columns.size)
        verifyEq(["referenced_column_name_1", "referenced_column_name_2"], reference.columns)
        verifyEq(0, canUseTableOptions.modifications.size)
        option := canUseTableOptions.foreignKey("foreign_key_name", ["column_name_1", "column_name_2"], reference)
        verifyEq(ForeignKeyTableOption#, option.typeof)
        verifyEq("foreign_key_name", (option as ForeignKeyTableOption).name)
        verifyEq(2, (option as ForeignKeyTableOption).columns.size)
        verifyEq(["column_name_1", "column_name_2"], (option as ForeignKeyTableOption).columns)
        verifyEq(reference, (option as ForeignKeyTableOption).reference)
        verifyEq(1, canUseTableOptions.modifications.size)
        verifyEq(option, canUseTableOptions.modifications[0])
    }

    **
    ** Tests the `CanUseTableOptions.primaryKey` method.
    **
    Void testPrimaryKey() {
        option := canUseTableOptions.primaryKey("primary_key_name", ["column_name_1", "column_name_2"])
        verifyEq(PrimaryKeyTableOption#, option.typeof)
        verifyEq("primary_key_name", (option as PrimaryKeyTableOption).name)
        verifyEq(2, (option as PrimaryKeyTableOption).columns.size)
        verifyEq(["column_name_1", "column_name_2"], (option as PrimaryKeyTableOption).columns)
        verifyEq(1, canUseTableOptions.modifications.size)
        verifyEq(option, canUseTableOptions.modifications[0])
    }

    **
    ** Tests the `CanUseTableOptions.references` method.
    **
    Void testReferences() {
        reference := canUseTableOptions.references("table_name", ["column_name_1", "column_name_2"])
        verifyEq(Reference#, reference.typeof)
        verifyEq("table_name", reference.table)
        verifyEq(2, reference.columns.size)
        verifyEq(["column_name_1", "column_name_2"], reference.columns)
        verifyEq(0, canUseTableOptions.modifications.size)
    }

    **
    ** Tests the `CanUseTableOptions.unique` method.
    **
    Void testUnique() {
        option := canUseTableOptions.unique("unique_name", ["column_name_1", "column_name_2"])
        verifyEq(UniqueTableOption#, option.typeof)
        verifyEq("unique_name", (option as UniqueTableOption).name)
        verifyEq(2, (option as UniqueTableOption).columns.size)
        verifyEq(["column_name_1", "column_name_2"], (option as UniqueTableOption).columns)
        verifyEq(1, canUseTableOptions.modifications.size)
        verifyEq(option, canUseTableOptions.modifications[0])
    }

}

**
** Provides a simple implementation of `CanUseColumnOptions` for testing.
**
internal class CanUseTableOptionsTestClass : CanUseTableOptions {

    **
    ** Stores the list of [Modifications]`Modification` for testing.
    **
    override Modification[] modifications := [,]

}
